<?php
/**
 * Created by PhpStorm.
 * User: 王峥宇
 * Date: 2019-04-23
 * Time: 14:38
 */

namespace app\shop\controller;

use think\Controller;
use think\Session;

class Index extends Base
{
    public function index()
    {
        //获取用户id
        $admin_uid = Session::get("admin_uid");
        //查出用户组rules
        $admin_info = db("auth_group g")
            ->join("jc_auth_group_access ga","g.id = ga.group_id")
            ->where("ga.uid",$admin_uid)
            ->field("g.rules")
            ->find();
        $where ['id'] = array("in",$admin_info['rules']);
        $where ['pid'] = 0;
        $whereDate['id']= array("in",$admin_info['rules']);
        $res=db('auth_rule')->where($where)->select();
        foreach($res as $k=>$v){
            $res[$k]['son']=db('auth_rule')->where($whereDate)->where('pid',$v['id'])->select();
        }
        return view('index',['res'=>$res]);
    }

    public function welcome()
    {
        $id = Session::get('id');
        $shop = db('shop')->where('id',$id)->find();
        $shopid = db('indent')->where('shopid',$shop['shopid'])->count();
        $shid = db('indent')->where('shopid',$shop['shopid'])->where('sid',3)->count();
        $this->assign('shid',$shid);
        $this->assign('shopid',$shopid);
        $this->assign('shop',$shop);
        return $this->fetch();
    }
}